/*Hm9gUKDDwtNjV7Mk8onAzuEHPbfUwAnfWyNcAQ3p3qQVroIHGgbouA/v3HeA4/n7*/
import { queryUrl, queryProfitUrl } from '../constants';
import { ajax, toast } from 'nc-lightapp-front';
import ampub from 'ampub';
import { CONTRACT_BILL_TYPE } from '../constants';

const { utils } = ampub;
const { getMultiLangByID } = utils.multiLangUtils;

export function linkCard(props, record, pkFiled, transtype) {
	let param = {
		id: record[pkFiled].value,
		transtype: transtype
	};
	let url = queryUrl;
	/* 2020.12版本 盘盈单轻量化，故修改为跳转到盘盈单 modified by zhangypm 2020-8-20
	if (transtype === 'HS-01' || transtype === 'HS') {
		let code = record[pkFiled].value + '<:>' + record['bill_code'].value;
		param['id'] = code;
		param['transtype'] = 'HP-01';
		url = queryProfitUrl;
	}
	*/
	ajax({
		url: url,
		data: param,
		success: (res) => {
			let { success, data } = res;
			if (success) {
				if (data) {
					if ([ 'HS-01', 'HS' ].includes(transtype) || transtype.startsWith(CONTRACT_BILL_TYPE)) {
						data['status'] = 'browse';
						data['current'] = '7';
					}
					props.openTo(data['url'], data);
				} else {
					toast({
						color: 'danger',
						content: getMultiLangByID('noauthorization-000001') /*国际化处理：您没有操作该应用的权限，请联系管理员为您分配权限*/
					});
				}
			}
		}
	});
}

/*Hm9gUKDDwtNjV7Mk8onAzuEHPbfUwAnfWyNcAQ3p3qQVroIHGgbouA/v3HeA4/n7*/